package myProj1;

import java.util.HashMap;
import java.util.Map;

public class Date {
	// month
	private String month;
	// date
	private int date;

	public static Map<String, Integer> mapMonth;

	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}

	public int getDate() {
		return date;
	}

	public void setDate(int date) {
		this.date = date;
	}

	@Override
	public String toString() {
		return (month.charAt(0)+"").toUpperCase()+month.substring(1, 3) + " " + date;
	}

	public Date(String month, int date) {
		super();
		this.month = month;
		this.date = date;

		mapMonth = new HashMap<String, Integer>();
		String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
		for (int i = 0; i < months.length; i++) {
			mapMonth.put(months[i], i + 1);
			mapMonth.put(months[i].toLowerCase(), i + 1);
		}
	}

	/**
	 * 
	 * @param anotherDate
	 * @return true if anotherDate is after current Date
	 */
	public boolean after(Date anotherDate) {
		if (mapMonth.get(this.month) < mapMonth.get(anotherDate.getMonth())) {
			return false;
		} else if (mapMonth.get(this.month) >= mapMonth.get(anotherDate.getMonth())) {
			return true;
		} else {
			if (this.date < anotherDate.getDate()) {
				return false;
			} else if (this.date >= anotherDate.getDate()) {
				return true;
			}
		}
		return false;
	}

	public boolean equals(Date anotherDate) {

		return getMonth().equalsIgnoreCase(anotherDate.getMonth()) && getDate() == anotherDate.getDate();
	}

	public static int getDaysOfMonth(String month) {

		if (Date.mapMonth.get(month) == 1 || Date.mapMonth.get(month) == 3 || Date.mapMonth.get(month) == 5
				|| Date.mapMonth.get(month) == 7 || Date.mapMonth.get(month) == 8 || Date.mapMonth.get(month) == 10
				|| Date.mapMonth.get(month) == 12) {
			return 31;
		} else if (Date.mapMonth.get(month) == 4 || Date.mapMonth.get(month) == 6 || Date.mapMonth.get(month) == 9
				|| Date.mapMonth.get(month) == 11) {
			return 30;
		} else {
			return 28;

		}
	}

}
